import { resetRouter } from '@/router'
import {trace} from "../../utils/trace"

import {
  createEnterprise, createLink,
  seoAudit, seoDel, seoDetail,
  seoForbid, seoSummary,
  words,
  wordsCheck,
  wordsDel,
  wordsKind,
  wordsQuery,
  seoQuery
} from "../../api/promote"

const getDefaultState = () => {
  return {
    words:[],
  }
}

const state = getDefaultState()

const mutations = {

  SET_WORDS: (state, words) => {
    state.words = words
  },
}

const actions = {

  // 违禁词库-新增 words
  words({commit}, data) {
    return new Promise((resolve, reject) => {
      words(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
// 违禁词库-更改使用范围 wordsKind
  wordsKind({commit}, data) {
    return new Promise((resolve, reject) => {
      wordsKind(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
// 违禁词库-删除 wordsDel
  wordsDel({commit}, data) {
    return new Promise((resolve, reject) => {
      wordsDel(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
// 违禁词库-列表 wordsQuery
  wordsQuery({commit}) {
    return new Promise((resolve, reject) => {
      wordsQuery().then(response => {
        const {data} = response
          commit("SET_WORDS",data);
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 违禁词-检查 wordsCheck
  wordsCheck({commit}, data) {
    return new Promise((resolve, reject) => {
      wordsCheck(data).then(response => {
        const {data} = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 新建企业推广 createEnterprise
  createEnterprise({commit}, data) {
    return new Promise((resolve, reject) => {
      createEnterprise(data).then(response => {
        const {data} = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 新建企业推广 createLink
  createLink({commit}, data) {
    return new Promise((resolve, reject) => {
      createLink(data).then(response => {
        const {data} = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 管理员审核服务 seoAudit
  seoAudit({commit}, data) {
    return new Promise((resolve, reject) => {
      seoAudit(data).then(response => {
        const {data} = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 禁止推广服务 seoForbid
  seoForbid({commit}, data) {
    return new Promise((resolve, reject) => {
      seoForbid(data).then(response => {
        const {data} = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //  获取推广列表  seoQuery
  seoQuery({commit}, data) {
    return new Promise((resolve, reject) => {
      seoQuery(data).then(response => {
        const {data} = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //  获取推广数据的总结 seoSummary
  seoSummary({commit}, data) {
    return new Promise((resolve, reject) => {
      seoSummary(data).then(response => {
        const {data} = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //  删除推广信息 seoDel
  seoDel({commit}, data) {
    return new Promise((resolve, reject) => {
      seoDel(data).then(response => {
        const {data} = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //  获取推广数据的详细信息 seoDetail
  seoDetail({commit}, data) {
    return new Promise((resolve, reject) => {
      seoDetail(data).then(response => {
        const {data} = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },


}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

